from django import template

from django.contrib.contenttypes.models import ContentType

from topics.models import Topic



register = template.Library()



@register.inclusion_tag("topics/topic_item.html", takes_context=True)
def show_topic(context, topic):
    return {
        "topic": topic,
        "group": context.get("group"),
    }


@register.tag(name="get_topics_for_group")
def do_get_topics_for_tribes(parser, token):
    """
    Provides the template tag {% get_topics_for_group GROUP as VARIABLE %}
    """
    try:
        _tagname, group_name, _as, context_name = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError(u"""get_topics_for_group tag syntax is as follows: 
            {%% get_topics_for_group GROUP as VARIABLE %%}""")
    return TopicsForGroupNode(group_name, context_name)
